package com.adv.ems.controller.client;

import com.adv.ems.constants.SystemConst;
import com.adv.ems.model.dto.APIRequest;
import com.adv.ems.model.dto.APIResponse;
import com.adv.ems.model.param.EnergySearchSubjectTreeParam;
import com.adv.ems.model.param.MeterHealthParam;
import com.adv.ems.model.vo.*;
import com.adv.ems.service.BaseDataService;
import com.adv.ems.service.EnergySearchService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/ems/client/energy/base")
public class BaseDataController {
    @Resource
    BaseDataService baseDataService;
    @Resource
    EnergySearchService energySearchService;

    @PostMapping("/item/list")
    public APIResponse<EnergyBaseItemListVO> itemList(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage) {
        return APIResponse.<EnergyBaseItemListVO>build().content(baseDataService.validItemList(acceptLanguage));
    }

    @PostMapping("/energy/list")
    public APIResponse<IndexEnergyInfoVO> energyList(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage) {
        return APIResponse.<IndexEnergyInfoVO>build().content(baseDataService.energyList(acceptLanguage));
    }
    @PostMapping("/subject/tree")
    public APIResponse<EnergySearchSubjectTreeVO> subjectTree(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                                              @RequestBody APIRequest<EnergySearchSubjectTreeParam> request) {
        return APIResponse.<EnergySearchSubjectTreeVO>build().content(energySearchService.subjectTree(request.getContent(), acceptLanguage));
    }

    @PostMapping("/circuit/diagram/tree")
    public APIResponse<EnergySearchCircuitDiagramTreeVO> diagramTree(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                                                     @RequestBody APIRequest<EnergySearchSubjectTreeParam> request) {
        return APIResponse.<EnergySearchCircuitDiagramTreeVO>build().content(energySearchService.diagramTree(request.getContent(), acceptLanguage));
    }

    @PostMapping("/meters/health")
    public APIResponse<MeterHealthVO> meterHealth(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                                  @RequestBody APIRequest<MeterHealthParam> request) {
        return APIResponse.<MeterHealthVO>build().content(energySearchService.meterHealth(request.getContent(), acceptLanguage));
    }
}
